package com.sscw.task.mqtt;

import com.guaike.core.mqtt.processor.MqttGateway;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.stereotype.Component;


@Slf4j
@Component
@AllArgsConstructor
public class MQTTProducer {

    private final MqttGateway mqttGateway;

    public void sendIoMessage(String topic, String message, Integer qosLevel) throws MqttException {
        log.info("终端发送mqtt消息，topic：{}，message：{}", topic, message);
        MqttMessage sendMessage = new MqttMessage(message.getBytes());
        sendMessage.setQos(qosLevel);
        mqttGateway.sendToMqtt(topic, qosLevel, message);
    }

}
